﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CodeGenerator.BaseUI;
using CodeGenerator.Common;
using System.IO;
using ICSharpCode.TextEditor.Document;
using CodeGenerator.Core;
using System.Collections;

namespace CodeGenerator.UI
{
    public partial class FrmSystemTemplateEdit : BaseFormEx
    {
        private string filePath = "";
        private FileType fileType;
        private string fileName;
        public FrmSystemTemplateEdit(string filePath, FileType fileType, string fileName)
        {
            InitializeComponent();

            this.filePath = filePath;
            this.fileType = fileType;
            this.fileName = fileName;
        }

        private void FrmSystemTemplateEdit_Load(object sender, EventArgs e)
        {
            StreamReader reader = new StreamReader(DirectoryUtil.FileToStream(filePath));

            string style = "C#";
            if (fileType == FileType.cs)
            {
                style = "C#";
            }
            else if (fileType == FileType.sql)
            {
                style = "TSQL";
            }
            FormatCodeHelper.FormatText(txt_TempleteFileInfo, style, reader.ReadToEnd());
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DirectoryUtil.Write(this.filePath, txt_TempleteFileInfo.Text);
              //  lbl_OperateResult.Text = "文件保存成功";
                MessageUtil.ShowTips("文件保存成功！");
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("保存模板文件信息：", ex);
            }
        }
    }
}
